
function updateOneInfo(num,info_id,pub_date) { 
		document.getElementById('updateThisInfo'+num).innerHTML = '<img src="/program/admin/images/wait.gif"/>';
		jQuery.ajax( {
			   type: 'POST',
			   url: 'updateOneInfo.jsp',
			   data: 'info_id='+info_id+'&pub_date='+pub_date+'&num='+num,
			   success: function(msg){
					document.getElementById('updateThisInfo'+num).innerHTML=msg;
				 }
			}); 
	}

function showDiv(val){
		if(document.getElementById("cat_div").style.display=="none"){
			document.getElementById("cat_div").style.display="";
		}else{
			document.getElementById("cat_div").style.display="none";
		}
	
}
function checkSub(val){
	alert("青海省海东市平安县科学大道118号");
	var cur_store=document.getElementById('cur_store').value;
	var limit_num=document.getElementById('limit_num').value;
	var buy_price = document.getElementById('price').value;
	var input_price = document.getElementById('input_price').value;
	var vmoney = document.getElementById('vmoney').value;
	var old_buyprice = document.getElementById('old_price').value;
	var team_num=document.getElementById('team_num').value;	
	var down_num=document.getElementById('down_num').value;
	var buy_limit=document.getElementById('buy_limit').value;
	var type=document.getElementById('type').value;
	if(document.getElementById('title').value==''){
		alert('请输入团购标题！');
		document.getElementById('title').focus();
		return false;
	}

	if(document.getElementById('title').value.length > 300){
		alert('团购标题字数限制在300字以内！');
		document.getElementById('title').focus();
		return false;
	}
	var cat_attr ="" ;
		if(document.getElementById('sort1').value != ''){
			cat_attr = '';
			cat_attr += document.getElementById('sort1').value+'|';
			if(document.getElementById('sort2').value!=''){
				cat_attr += document.getElementById('sort2').value+'|';
			 }
		    if(document.getElementById('sort3').value!=''){
				cat_attr += document.getElementById('sort3').value+'|';
			 }
		}
	
		if(cat_attr!=""){
			document.getElementById('cat_attr').value=cat_attr;	
		}else if(document.getElementById('cat_attr').value==""){
			 alert("请选择商品分类");
		  	 document.getElementById('sort1').focus();
		  	 return false;
		}
	if(document.getElementById("team_type").value=="")
    {
       alert("请选择团购类型");
	   document.getElementById('team_type').focus();
	   return false;
    }
	if((type==1&&cur_store=='')||cur_store=='0'){
		alert('请输入库存数量！');
		document.getElementById('cur_store').focus();
		return false;
	}
	
	if(document.getElementById('weight').value=='')
	  {
	     alert('请输入商品重量！');
	     document.getElementById('weight').focus();
		return false;
	  }
  if(document.getElementById('price_unit').value=='')
  {
      alert('请选择计价单位！');
     document.getElementById('price_unit').focus();
		return false;
  }
	
	if(limit_num==''){
		alert('请输入限购数量！');
		document.getElementById('limit_num').focus();
		return false;
	}
	if(parseInt(limit_num)<0){
		alert('限购数量不能小于0！');
		document.getElementById('limit_num').focus();
		return false;
	}
	if(type==1&&parseInt(cur_store)<0){
		alert('库存数量不能小于0！');
		document.getElementById('cur_store').focus();
		return false;
	}
	if(type==1&&parseInt(limit_num)>parseInt(cur_store)){
		alert('限购数量不能大于库存数量！');
		document.getElementById('limit_num').focus();
		return false;
	}
	if(input_price==''||parseInt(input_price)<=0){
		alert('请输入团购进价！');
		document.getElementById('input_price').focus();
		return false;
	}
	if(!checkFloat('input_price')){
		alert('进价格式不正确，正确格式如88888.88！');
		document.getElementById('input_price').focus();
		return false;
	}
	if(buy_price==''){
		alert('请输入团购价格！');
		document.getElementById('price').focus();
		return false;
	}
	if(vmoney!=''&&parseFloat(vmoney)>parseFloat(buy_price)){
		alert('虚拟币支付额不能大于团购价格！');
		document.getElementById('vmoney').focus();
		return false;
	}

	if(!checkFloat('price')){
		alert('团购价格格式不正确，正确格式如88888.88！');
		document.getElementById('price').focus();
		return false;
	}
	
	if(old_buyprice==''){
		alert('请输入团购原价！');
		document.getElementById('old_price').focus();
		return false;
	}

	if(!checkFloat('old_price')){
		alert('团购原价格式不正确，正确格式如88888.88！');
		document.getElementById('old_price').focus();
		return false;
	}
	
	if(parseFloat(buy_price)>=parseFloat(old_buyprice)){
		alert('团购价格不能高于原价格！');
		document.getElementById('price').focus();
		return false;
	}
	
	if(document.getElementById('start_date').value==''){
		alert('请选择开始时间！');
		document.getElementById('start_date').focus();
		return false;
	}
	
	if(document.getElementById('end_date').value==''){
		alert('请选择结束时间！');
		document.getElementById('end_date').focus();
		return false;
	}
	
	if(team_num==''){
		alert('请输入团购人数！');
		document.getElementById('team_num').focus();
		return false;
	}
	
	if(down_num==''){
		alert('请输入最低团购人数！');
		document.getElementById('down_num').focus();
		return false;
	}
	if(buy_limit==''){
		alert('请输入单次限购数量！');
		document.getElementById('buy_limit').focus();
		return false;
	}
	if(parseInt(limit_num)>0&&(parseInt(buy_limit)>parseInt(limit_num))){
		alert('单次限购数量不能大于限购数量！');
		document.getElementById('buy_limit').focus();
		return false;
	}
	
    if(CKEDITOR.instances.content.getData()=="")
	{
    	alert("请输入团购详细信息！");
    	CKEDITOR.instances.content.focus();
		return false;
	}
	
	if(document.getElementById('seller').value==''){
		alert('请输入卖家名称！');
		document.getElementById('seller').focus();
		return false;
	}
	var con_num = document.getElementById('con_num').value;
	var contact_val = '';
	
	var urlreg=/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\:+!]*([^<>])*$/;
	var url ="";
	var phone="";
	for(var i=1;i<=con_num*1-1;i++){
		url=document.getElementById('shop_web'+i).value;
		phone=document.getElementById('shop_phone'+i).value;
	    if(url!=null && url !=''){
	     	url = "<a href='"+url+"' target='_blank' >"+url+"</a>" ;
	     }
		if(document.getElementById('shop_name'+i).value!='' && phone!=''){
			contact_val += document.getElementById('shop_name'+i).value+'|'+document.getElementById('shop_addr'+i).value+'|'+phone+'|'+url+'|,';
		}else{
			alert('店名和电话号码不能为空！');
			document.getElementById('shop_name'+i).focus()
			return false;
		}
	    if(!isTel(phone)){
	    	 alert("号码格式不正确!");
	    	 document.getElementById('shop_phone'+i).focus()
		     return false;
	    }
	}
	document.getElementById('contact').value = contact_val;
	if(document.getElementById('contact').value==''){
		alert('请输入卖家联系方式！');
		return false;
	}
	var user_id=document.getElementById('user_id').value ;
	if(user_id==''){
		document.getElementById('user_id').value=document.getElementById('user_idbak').value;
	}
	
	if(val=='add')
		document.addForm.submit();
	else
		document.updateForm.submit();
}

function search(){
	var class_attr=""; 
  if(document.getElementById("sort1").value!="")
  {
      class_attr = document.getElementById("sort1").value+"|"; 
  }

  if(document.getElementById("sort2").value!="")
  {
      class_attr += document.getElementById("sort2").value+"|"; 
  }

  if(document.getElementById("sort3").value!="")
  {
      class_attr += document.getElementById("sort3").value+"|"; 
  }
  
  document.getElementById("s_class_attr").value = class_attr;	 
	document.indexForm.submit();
}

function checkFloat(val){
	var myreg = /^((\d+\.\d*[1-9]\d*)|(\d*[1-9]\d*\.\d+)|(\d*[1-9]\d*))$/;
	if(myreg.test(document.getElementById(val).value)) return true;
	return false;
}

//判断是否为数字
//是返回true
//否返回false
function checkInt(val){
	if(!isNaN(document.getElementById(val).value)) return true;
	return false;
}

function isTel(str){
       var reg=/^([0-9]|[\-])+$/g ;
       if(str.length<7 || str.length>18){
        return false;
       }
       else{
         return reg.exec(str);
       }
}



function setOneClass(type,sort){
	Ts_categoryInfo.getCatClassByUpId("000000000000000",type,function(data){
	DWRUtil.removeAllOptions(sort);
	DWRUtil.addOptions(sort,{'':'请选择'});
	DWRUtil.addOptions(sort,data);
	});
	
} 
 

function setSecondClass(val,type,sort2,sort3) {
 
	Ts_categoryInfo.getCatClassByUpId(val, type, function(data){
	DWRUtil.removeAllOptions(sort2);
	DWRUtil.addOptions(sort2,{'':'请选择'});
	DWRUtil.addOptions(sort2,data);
	DWRUtil.removeAllOptions(sort3);
	DWRUtil.addOptions(sort3,{'':'请选择'});
	});
} 
function setTherdClass(val,type,sort3){ 
	Ts_categoryInfo.getCatClassByUpId(val, type,  function(data){
	DWRUtil.removeAllOptions(sort3);
	DWRUtil.addOptions(sort3,{'':'请选择'});
	DWRUtil.addOptions(sort3,data);	
	});
} 


 function showLinkCompany(flag){
 	if(document.getElementById("show_seller").style.display=="none"){
 		document.getElementById("show_seller").style.display="";
 		document.getElementById("seller").style.display="none";
 		document.getElementById("_seller").style.display="none";
 		return false;
 	}
   var info_id = document.getElementById('info_id').value; 
   var sort11 = document.getElementById('sort11').value; 
   var sort22 = document.getElementById('sort22').value; 
   var sort33 = document.getElementById('sort33').value; 
   if(sort11!=""&&sort22!=''){
   		sort11 +="|"+sort22;
   }
   if(sort33!=""){
   		sort11 +="|"+sort33;
   }
   if(sort11==""){
   	alert("请选择分类查询");
   	return false;
   }
   var data = Math.round(Math.random()* 10000);   
   var bURL = "&flag="+flag+"&info_id="+info_id+"&cat_attr="+sort11+"&data="+data;
   var gURL = "/program/admin/teambuy/showMoreCompany.jsp?height=400&width=600"+bURL;  
   var title ="企业会员";  
   TB_show(title,gURL,true);                                                       

}
 
function linkCompanyOpr(flag,info_id,cust_id,cust_name,area_attr,phone,website)
{
		var req_url="&cust_id="+cust_id+"&seller="+encodeURI(encodeURI(cust_name))+"&shop_name1="+encodeURI(encodeURI(cust_name))+"&shop_addr1="+encodeURI(encodeURI(area_attr))+"&shop_phone1="+phone+"&shop_web1="+encodeURI(encodeURI(website));
		if(flag=="add")
		   document.location.href="/program/admin/teambuy/addInfo.jsp?info_id="+info_id+req_url;
		else
		   document.location.href="/program/admin/teambuy/updateInfo.jsp?info_id="+info_id+req_url;	 
		 TB_remove();
}

function addContact(){
	var con_num = document.getElementById('con_num').value;
	if(con_num*1 <=5){
		var con_div = '<div id="div_shop'+con_num+'">店名：<input type="text" name="shop_name'+con_num+'" id="shop_name'+con_num+'" size="30" maxlength="50"/>&nbsp;<br/>';
			con_div	+= '地址：<input type="text" name="shop_addr'+con_num+'" id="shop_addr'+con_num+'" size="50" maxlength="60"/><br/>';
			con_div	+='电话号码：<input type="text" name="shop_phone'+con_num+'" id="shop_phone'+con_num+'" size="20" maxlength="20"/>&nbsp;';
			con_div	+='网址：<input type="text" name="shop_web'+con_num+'" id="shop_web'+con_num+'" size="20" maxlength="20"/>&nbsp;';
			con_div	+='<a href="javascript:delContact('+con_num+')">删除</a>&nbsp;<br/></div>';
		document.getElementById('contactDiv').innerHTML = document.getElementById('contactDiv').innerHTML + con_div;
		document.getElementById('con_num').value = con_num*1 +1;
	}else{
		alert('最多只能添加5个联系信息！');
	}
}

function delContact(con_num){
	var div=document.getElementById("div_shop"+con_num);
	 div.parentNode.removeChild(div);  
	document.getElementById('con_num').value = (document.getElementById('con_num').value)*1-1;
}

function ChangeClassStyle(){
	document.getElementById("flag_code").value = "1";
	document.getElementById("classId1").style.display="none";
	document.getElementById("classId2").style.display="";
}
